<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Construct a non-executable tar or zip archive object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phardata.compressfiles.html">PharData::compressFiles</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phardata.converttodata.html">PharData::convertToData</a></div>
 <div class="up"><a href="class.phardata.html">PharData</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="phardata.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PharData::__construct</h1>
  <p class="verinfo">(PHP &gt;= 5.3.0, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">PharData::__construct</span> &mdash; <span class="dc-title">Construct a non-executable tar or zip archive object</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-phardata.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>PharData::__construct</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$fname</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$alias</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code><span class="initializer"> = <strong><code>Phar::TAR</code></strong></span></span>
  ]]] )</div>


 </div>

 <div class="refsect1 parameters" id="refsect1-phardata.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">fname</code></em></dt>

     <dd>

      <p class="para">
       Path to an existing tar/zip archive or to-be-created archive
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">flags</code></em></dt>

     <dd>

      <p class="para">
       Flags to pass to <a href="class.phar.html" class="classname">Phar</a> parent class
       <a href="class.recursivedirectoryiterator.html" class="classname">RecursiveDirectoryIterator</a>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">alias</code></em></dt>

     <dd>

      <p class="para">
       Alias with which this Phar archive should be referred to in calls to stream
       functionality.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">format</code></em></dt>

     <dd>

      <p class="para">
       One of the
       <a href="phar.constants.html#phar.constants.fileformat" class="link">file format constants</a>
       available within the <a href="class.phar.html" class="classname">Phar</a> class.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phardata.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a> if called twice;
   <a href="class.unexpectedvalueexception.html" class="classname">UnexpectedValueException</a> if the Phar archive can&#039;t
   be opened.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-phardata.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-687">
    <p><strong>Example #1 A <span class="function"><strong>PharData::__construct()</strong></span> example</strong></p>
     <div class="example-contents"><p>
      <div class="example-contents">
       <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PharData</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/my.tar'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURRENT_AS_FILEINFO&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">KEY_AS_FILENAME</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">UnexpectedValueException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;open&nbsp;my.tar'</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">BadMethodCallException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'technically,&nbsp;this&nbsp;cannot&nbsp;happen'</span><span style="color: #007700">;<br />}<br />echo&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar:///path/to/my.tar/example.txt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </p></div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phardata.compressfiles.html">PharData::compressFiles</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phardata.converttodata.html">PharData::convertToData</a></div>
 <div class="up"><a href="class.phardata.html">PharData</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
